package cn.itsource.service.impl;

import cn.itsource.domain.DriverSummaryInfo;
import cn.itsource.openfeign.DriverSummaryOpenFeign;
import cn.itsource.openfeign.ValuationOpenFeign;
import cn.itsource.pojo.domain.OrderBill;
import cn.itsource.mapper.OrderBillMapper;
import cn.itsource.pojo.vo.DriverEndOrderBillVo;
import cn.itsource.result.JSONResult;
import cn.itsource.service.IOrderBillService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * <p>
 * 订单账单表 服务实现类
 * </p>
 *
 * @author tt
 * @since 2024-09-20
 */
@Service
public class OrderBillServiceImpl extends ServiceImpl<OrderBillMapper, OrderBill> implements IOrderBillService {

    @Autowired
    private ValuationOpenFeign valuationOpenFeign;

    @Override
    public JSONResult getOrderBill(String orderNo) {

        OrderBill one = super.getOne(new LambdaQueryWrapper<OrderBill>()
                .eq(OrderBill::getOrderNo, orderNo));
        if (one == null){
            return JSONResult.error("未查询到该账单");
        }
        JSONResult proportion = valuationOpenFeign.getProportion();
        //使用openfeign进行远程调用  如果返回方返回时对象 会变成 linkedHashMap
        //使用openfeign进行远程调用  如果返回方返回时小数 会变成 Double
        //使用openfeign进行远程调用  如果返回方返回时整数 会变成 Integer
        DriverEndOrderBillVo driverEndOrderBillVo = new DriverEndOrderBillVo();
        BeanUtils.copyProperties(one,driverEndOrderBillVo);
        driverEndOrderBillVo.setTotalProportion(new BigDecimal(proportion.getData().toString()));
        return JSONResult.success(driverEndOrderBillVo);
    }
}
